<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改产品图片')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-images-edit" th:object="${images}">
        <input id="imagesId" name="imagesId" type="hidden" th:field="*{imagesId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="imagesName" id="imagesName" th:field="*{imagesName}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片选择：</label>
            <div class="col-sm-8">
                <select class="form-control" name="urlId" onchange="imagesNodeId(this)">
                    <option th:each="url:${url}" th:value="${url.urlId}" th:selected="${url.urlId eq images.urlId}">[[${url.urlId}]]</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-8" id="imagesDivId">

            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "product/images";

    $("#form-images-edit").validate({
        onkeyup: false,
        rules:{
            typeSort:{
                digits:true
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-images-edit').serialize());
        }
    }

    function imagesNodeId(obj) {
        $.ajax({
            url: prefix + "/changeImagesUrl",
            data:{urlId:obj.value},
            dataType:"json",
            type:"post",
            async:"true",
            success:function (data) {
                if(data.code == 0){
                    $("#imagesDivId").empty();
                    // $("#imagesUrlId").attr("src",data.data.imagesUrl);
                    $("#imagesDivId").append("<img src=\""+data.data.urlSrc+"\" width=\"300px\" height=\"300px\">")
                }else {
                    console.log(data.msg);
                }
            }
        });
    }
</script>
</body>
</html>
